/*!The Treasure Box Library
 * 
 * TBox is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * TBox is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with TBox; 
 * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
 * 
 * Copyright (C) 2009 - 2015, ruki All rights reserved.
 *
 * @author		ruki
 * @file		state.h
 *
 */
#ifndef TB_PREFIX_STATE_H
#define TB_PREFIX_STATE_H

/* //////////////////////////////////////////////////////////////////////////////////////
 * includes
 */
#include "config.h"
#include "type.h"

/* //////////////////////////////////////////////////////////////////////////////////////
 * macros
 */

/// the state define
#define TB_STATE_DEFINE(type, state) 	(((type) << 16) | (state))

/* //////////////////////////////////////////////////////////////////////////////////////
 * types
 */

/// the state type enum
typedef enum __tb_state_type_e
{
 	TB_STATE_TYPE_NONE 	= 0
, 	TB_STATE_TYPE_SOCK 	= 1
, 	TB_STATE_TYPE_HTTP 	= 2

}tb_state_type_e;

/// the state enum
typedef enum __tb_state_e
{
	TB_STATE_OK 						= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 0)
,	TB_STATE_FAILED 					= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 1)
,	TB_STATE_KILLED 					= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 2)
,	TB_STATE_PAUSED 					= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 3)
,	TB_STATE_CLOSED 					= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 4)
,	TB_STATE_PENDING 					= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 5)
,	TB_STATE_TIMEOUT 					= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 6)
,	TB_STATE_WAIT_FAILED 				= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 7)
,	TB_STATE_NOT_SUPPORTED 				= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 8)
,	TB_STATE_UNKNOWN_ERROR 				= TB_STATE_DEFINE(TB_STATE_TYPE_NONE, 9)

,	TB_STATE_SOCK_DNS_FAILED 			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 1)
,	TB_STATE_SOCK_CONNECT_FAILED		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 2)
,	TB_STATE_SOCK_CONNECT_TIMEOUT		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 3)
,	TB_STATE_SOCK_RECV_TIMEOUT			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 4)
,	TB_STATE_SOCK_SEND_TIMEOUT			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 5)
,	TB_STATE_SOCK_RECV_FAILED			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 6)
,	TB_STATE_SOCK_SEND_FAILED			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 7)
,	TB_STATE_SOCK_UNKNOWN_ERROR			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 8)
,	TB_STATE_SOCK_SSL_FAILED			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 9)
,	TB_STATE_SOCK_SSL_TIMEOUT			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 10)
,	TB_STATE_SOCK_SSL_WANT_READ			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 11)
,	TB_STATE_SOCK_SSL_WANT_WRIT			= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 12)
,	TB_STATE_SOCK_SSL_WAIT_FAILED		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 13)
,	TB_STATE_SOCK_SSL_READ_FAILED		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 14)
,	TB_STATE_SOCK_SSL_WRIT_FAILED		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 15)
,	TB_STATE_SOCK_SSL_NOT_SUPPORTED		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 16)
,	TB_STATE_SOCK_SSL_UNKNOWN_ERROR		= TB_STATE_DEFINE(TB_STATE_TYPE_SOCK, 17)

,	TB_STATE_HTTP_RESPONSE_204 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 1)
,	TB_STATE_HTTP_RESPONSE_300 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 2)
,	TB_STATE_HTTP_RESPONSE_301 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 3)
,	TB_STATE_HTTP_RESPONSE_302 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 4)
,	TB_STATE_HTTP_RESPONSE_303 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 5)
,	TB_STATE_HTTP_RESPONSE_304 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 6)
,	TB_STATE_HTTP_RESPONSE_400 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 7)
,	TB_STATE_HTTP_RESPONSE_401 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 8)
,	TB_STATE_HTTP_RESPONSE_402 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 9)
,	TB_STATE_HTTP_RESPONSE_403 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 10)
,	TB_STATE_HTTP_RESPONSE_404 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 11)
,	TB_STATE_HTTP_RESPONSE_405 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 12)
,	TB_STATE_HTTP_RESPONSE_406 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 13)
,	TB_STATE_HTTP_RESPONSE_407 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 14)
,	TB_STATE_HTTP_RESPONSE_408 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 15)
,	TB_STATE_HTTP_RESPONSE_409 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 16)
,	TB_STATE_HTTP_RESPONSE_410 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 17)
,	TB_STATE_HTTP_RESPONSE_411 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 18)
,	TB_STATE_HTTP_RESPONSE_412 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 19)
,	TB_STATE_HTTP_RESPONSE_413 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 20)
,	TB_STATE_HTTP_RESPONSE_414 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 21)
,	TB_STATE_HTTP_RESPONSE_415 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 22)
,	TB_STATE_HTTP_RESPONSE_416 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 23)
,	TB_STATE_HTTP_RESPONSE_500 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 24)
,	TB_STATE_HTTP_RESPONSE_501 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 25)
,	TB_STATE_HTTP_RESPONSE_502 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 26)
,	TB_STATE_HTTP_RESPONSE_503 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 27)
,	TB_STATE_HTTP_RESPONSE_504 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 28)
,	TB_STATE_HTTP_RESPONSE_505 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 29)
,	TB_STATE_HTTP_RESPONSE_506 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 30)
,	TB_STATE_HTTP_RESPONSE_507 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 31)
,	TB_STATE_HTTP_RESPONSE_UNK 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 32)
,	TB_STATE_HTTP_RESPONSE_NUL 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 33)
,	TB_STATE_HTTP_REQUEST_FAILED 		= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 34)
,	TB_STATE_HTTP_REDIRECT_FAILED 		= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 35)
,	TB_STATE_HTTP_POST_FAILED 			= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 36)
,	TB_STATE_HTTP_RANGE_INVALID 		= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 37)
,	TB_STATE_HTTP_GZIP_NOT_SUPPORTED	= TB_STATE_DEFINE(TB_STATE_TYPE_HTTP, 38)

}tb_state_e;

/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */

/*! the state string
 *
 * @param state 	the state
 *
 * @return 			the state string
 */
tb_char_t const* 	tb_state_cstr(tb_size_t state);

#endif


